package day0414;

import java.util.Arrays;

public class Test8 {

    public static int[] addElement(int[] arr, int element) {
        int oldLength = arr.length;
        int[] newArr = new int[oldLength *3/2 +1];
        for (int i = 0; i < oldLength; i++) {
            newArr[i] = arr[i];
        }
        newArr[oldLength] = element;
        return newArr;
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5};
        System.out.println("原数组: " + Arrays.toString(arr));
        int newElement = 6;
        arr = addElement(arr, newElement);
        System.out.println("添加元素 " + newElement + " 后的数组: " + Arrays.toString(arr));
    }
}    